﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<table id="AD_Index_grid" class="easyui-datagrid" style="width:100%;" title="AD设置" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#AD_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            @*<th data-options="field:'ck',checkbox:true"></th>*@
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="AD_Index_tb" style="padding:2px 5px;">
    <input class="easyui-textbox" label="OU:" style="width:220px" labelalign="right" labelwidth="70px" id="AD_Index_txtOUName" />
    <a href="javascript:void(0);" id="AD_Index_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="Query()" style="width:110px;height:30px;">查询</a>
    <a href="javascript:void(0);" id="AD_Index_btnGetAdd" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="LQ()" style="width:110px;height:30px;">拉取</a>
    <a href="javascript:void(0);" id="AD_Index_btnTB" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="TB()" style="width:110px;height:30px;">同步</a>
    <a href="javascript:void(0);" id="AD_Index_btnTB" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="Modify()" style="width:110px;height:30px;">AD配置</a>
</div>
<div id="AD_Index_winPZ" class="easyui-window" title="AD配置" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:300px;padding:10px;" maximizable="false" minimizable="false">
    <iframe id="AD_Index_frmPZ" src="" frameborder="0" scrolling="no" width="100%" height="300px"></iframe>
</div>
<script>
    $(document).ready(function () {
        $('#AD_Index_grid').datagrid({
            url: '/AD/Get_ajaxADInfo',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });

        InitPagenation();
    });
    function Query() {
        var ouname = $('#AD_Index_txtOUName').val();
        $('#AD_Index_grid').datagrid('options').url = '/AD/Get_ajaxADInfo?ouname=' + ouname;
        $('#AD_Index_grid').datagrid('load');
    }
    function LQ()
    {
        $.messager.confirm('提示', '确定是否拉取？', function (r) {
            if (r) {
                $.ajax({
                    url: '/AD/Get_ADInfo',
                    type: 'post',
                    dataType: 'text',
                    //data: { 'result': result, 'id': id, 'suggest': suggest},
                    success: function (data) {
                        if (data == '1') {
                            $.messager.alert('提示', '拉取成功', 'info');
                            $('#AD_Index_grid').datagrid('options').url = '/AD/Get_ajaxADInfo',
                                $('#AD_Index_grid').datagrid('load');
                        }
                        else { $.messager.alert('提示', '请检查AD配置！', 'info');}
                    }
                });
            }
        })
    }
    function TB()
    {
        $.messager.confirm('提示', '确定是否同步？', function (r) {
            if (r) {
                $.ajax({
                    url: '/AD/tb',
                    type: 'post',
                    dataType: 'json',
                    // data: { 'result': result, 'id': id, 'suggest': suggest},
                    success: function (data) {
                        $.messager.alert('提示', '同步成功', 'info');
                        //$('#AD_Index_grid').datagrid('options').url ='/AD/Get_ajaxADInfo',
                        //    $('#AD_Index_grid').datagrid('load');
                    }
                });
            }
        })
    }
    function Modify()
    {
        document.getElementById('AD_Index_frmPZ').src = '/AD/ADPZ';
        $('#AD_Index_winPZ').window('open');
    }
    function InitPagenation() {
        //设置分页控件
        var p = $('#AD_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#AD_Index_grid').datagrid('options').url = '/AD/Get_ajaxADInfoPager?num=' + num + '&size=' + size;
        $('#AD_Index_grid').datagrid('reload');
        $('#AD_Index_grid').datagrid('options').pageNumber = num;
        $('#AD_Index_grid').datagrid('options').pageSize = size;
        return;
    }
</script>

